﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing.plaf.basic {
    import flash.events.*;
    import org.aswing.*;
    import org.aswing.geom.*;
    import org.aswing.plaf.*;
    import org.aswing.event.*;
    import flash.ui.*;

    public class BasicViewportUI extends BaseComponentUI {

        protected var viewport:JViewport;

        override public function installUI(_arg1:Component):void{
            this.viewport = JViewport(_arg1);
            this.installDefaults();
            this.installListeners();
        }
        override public function uninstallUI(_arg1:Component):void{
            this.viewport = JViewport(_arg1);
            this.uninstallDefaults();
            this.uninstallListeners();
        }
        protected function getPropertyPrefix():String{
            return ("Viewport.");
        }
        protected function installDefaults():void{
            var _local1:String = this.getPropertyPrefix();
            LookAndFeel.installColorsAndFont(this.viewport, _local1);
            LookAndFeel.installBorderAndBFDecorators(this.viewport, _local1);
            LookAndFeel.installBasicProperties(this.viewport, _local1);
        }
        protected function uninstallDefaults():void{
            LookAndFeel.uninstallBorderAndBFDecorators(this.viewport);
        }
        protected function installListeners():void{
            this.viewport.addEventListener(FocusKeyEvent.FOCUS_KEY_DOWN, this.__onKeyDown);
            this.viewport.addEventListener(MouseEvent.MOUSE_WHEEL, this.__onMouseWheel);
        }
        protected function uninstallListeners():void{
            this.viewport.removeEventListener(FocusKeyEvent.FOCUS_KEY_DOWN, this.__onKeyDown);
            this.viewport.removeEventListener(MouseEvent.MOUSE_WHEEL, this.__onMouseWheel);
        }
        private function __onMouseWheel(_arg1:MouseEvent):void{
            if (!((this.viewport.isEnabled()) && (this.viewport.isShowing()))){
                return;
            };
            var _local2:IntPoint = this.viewport.getViewPosition();
            if (_arg1.shiftKey){
                _local2.x = (_local2.x - (_arg1.delta * this.viewport.getHorizontalUnitIncrement()));
            } else {
                _local2.y = (_local2.y - (_arg1.delta * this.viewport.getVerticalUnitIncrement()));
            };
            this.viewport.setViewPosition(_local2);
        }
        private function __onKeyDown(_arg1:FocusKeyEvent):void{
            if (!((this.viewport.isEnabled()) && (this.viewport.isShowing()))){
                return;
            };
            var _local2:uint = _arg1.keyCode;
            var _local3:IntPoint = this.viewport.getViewPosition();
            switch (_local2){
                case Keyboard.UP:
                    _local3.move(0, -(this.viewport.getVerticalUnitIncrement()));
                    break;
                case Keyboard.DOWN:
                    _local3.move(0, this.viewport.getVerticalUnitIncrement());
                    break;
                case Keyboard.LEFT:
                    _local3.move(-(this.viewport.getHorizontalUnitIncrement()), 0);
                    break;
                case Keyboard.RIGHT:
                    _local3.move(this.viewport.getHorizontalUnitIncrement(), 0);
                    break;
                case Keyboard.PAGE_UP:
                    if (_arg1.shiftKey){
                        _local3.move(-(this.viewport.getHorizontalBlockIncrement()), 0);
                    } else {
                        _local3.move(0, -(this.viewport.getVerticalBlockIncrement()));
                    };
                    break;
                case Keyboard.PAGE_DOWN:
                    if (_arg1.shiftKey){
                        _local3.move(this.viewport.getHorizontalBlockIncrement(), 0);
                    } else {
                        _local3.move(0, this.viewport.getVerticalBlockIncrement());
                    };
                    break;
                case Keyboard.HOME:
                    _local3.setLocationXY(0, 0);
                    break;
                case Keyboard.END:
                    _local3.setLocationXY(int.MAX_VALUE, int.MAX_VALUE);
                    break;
                default:
                    return;
            };
            this.viewport.setViewPosition(_local3);
        }

    }
}//package org.aswing.plaf.basic 
